
clear 
set more off

** Set directory
cd "C:\Users\14128\OneDrive - University of Pittsburgh\Research_Projects\LASA\Datos"   // here you should include your own directory

*****************************************************************
* Bolivia_2002_2006
*****************************************************************
{
*Calling the data 
 import spss using  ".\Bolivia\BASEDATOS_BOLIVIA_47.sav", clear
 
*****************************************************************
* Recoding Variables
***************************************************************** 
{
gen wave=1
 drop legis 
gen legis = 2006
* Ideology 
gen ID1 = p58 // 1 left 
replace ID1=. if  p58>11
* Ideology Party
gen ID2=p59 // 1 left 
replace ID2=. if  p59>11

*--------------------------
* Party
*--------------------------
gen party = "."
replace party = "BOL_MNR" if partido ==2 
replace party = "BOL_MIR" if partido ==3
replace party = "BOL_UCS" if partido ==4
replace party = "BOL_NFR" if partido ==5
replace party = "BOL_MAS" if partido ==6
replace party = "BOL_MIP" if partido ==7
replace party = "BOL_Other" if partido>7

drop partido 

gen partido=party

// Attendance to church
//gen church_attend=p70 
//replace church_attend=. if  p70==9

*--------------------------
* Religious
*--------------------------
* Religious label  Are you a  believer?
* Religious
gen religious =. 
replace religious = 1 if p60==1 
replace religious = 0 if p60==4 

lab define bel ///
	0 "Nonbeliever" ///
	1 "Believer"
lab val religious bel


*--------------------------
* Religious Catholic
*--------------------------
gen rel_catholic=1 if p60a==1
replace rel_catholic=0 if religious==1 & rel_catholic~=1

*--------------------------
* Religious Evangelical
*--------------------------
gen rel_evangelical=1 if p60a==3
replace rel_evangelical=0 if religious==1 & rel_evangelical~=1

*--------------------------
* Religious Other
*--------------------------
gen rel_other=1 if p60a~=1 & religious==1 &  p60a~=.
replace rel_other=0 if religious==1 & rel_catholic==1

*--------------------------
* Abortion
*--------------------------
gen val_abortion = p65 if p65<11

lab define VAL21 ///
	2 "Totally against" ///
	10 "Totally agree"
lab val val_abortion VAL21


*--------------------------
* Education
*--------------------------
gen education=p67 if p67<7


lab define uni312 ///
	1 "No education" ///
	6 "Graduate studies"
lab val education uni312
*--------------------------
* Gender
*--------------------------
gen female=1 if p62==2
replace female=0 if p62==1

* Sex label
lab define UNION ///
	0 "Men" ///
	1 "Women"
lab val female UNION

*--------------------------
* Age
*--------------------------
gen age=p63 if p63<100




*-----------------------
* Economy regulada
*-----------------------
gen eco_regulated = p28*2 if p28<7
lab define EMI_22 ///
	2 "State" ///
	10 "Market"
lab val eco_regulated EMI_22

*-----------------------
* Free education university
*-----------------------
gen eco_education_u= round(p2907*7/4) if p2907<7

lab define eco_education_u2 ///
	2 "Against" ///
	7 "In Favor"
lab val eco_education_u eco_education_u2

*-----------------------
* Price control
*-----------------------
gen eco_prices= round(p2901) if p2901<7

lab define eco_prices ///
	1 "Against" ///
	4 "In Favor"
lab val eco_prices eco_prices

*-----------------------
* Free education primary
*-----------------------
gen eco_education_p= round(p2902) if p2902<7

lab val eco_education_p eco_prices

*-----------------------
* Free education secondary
*-----------------------
gen eco_education_s= round(p2902) if p2902<7

lab val eco_education_s eco_prices

*-----------------------
* Subside to housing
*-----------------------
gen eco_housing= round(p2903) if p2903<7

lab val eco_housing eco_prices

*-----------------------
* Employment
*-----------------------
gen eco_employment= round(p2904*7/4) if p2904<7


lab val eco_employment eco_education_u2

*-----------------------
* Unemployment
*-----------------------
gen eco_unemployment= round(p2908) if p2908<7

lab val eco_unemployment eco_prices

*-----------------------
* Pensions
*-----------------------
gen eco_pensions= round(p2905*7/4) if p2905<7


lab val eco_pensions eco_education_u2

*-----------------------
* Environment
*-----------------------
gen eco_environment= round(p2909) if p2909<7

lab val eco_environment eco_prices

*-----------------------
* Basic necessity
*-----------------------
gen eco_necessity= round(p2910) if p2910<7

lab val eco_necessity  eco_prices


*-----------------------
* Tax
*-----------------------
gen eco_tax = p34 if p34<6
lab define taxes ///
	1 "Direct" ///
	2 "Indirect" ///
	3 "No more taxes"
lab val eco_tax taxes

*-----------------------
* Privatization
*-----------------------
gen eco_private = p35 if p35<6

lab define private ///
	1 "In favor" ///
	5 "Against"
lab val eco_private private
*-----------------------
* Religious values
*-----------------------
gen val_religious = p61 if p61<11
lab define secu ///
	1 "Christian" ///
	10 "Secular"
lab val val_religious secu


*-----------------------
* Divorce
*-----------------------
gen val_divorce = p64 if p64<11
lab define div ///
	1 "Against" ///
	10 "In favor"
lab val val_divorce div

}





// Labeling variables
{
lab var nestu "Study number"
lab var pais "Country name"
lab var partido "Party name (alphanumeric)"
lab var legis "Legislature"
lab var ID1 "Ideology"
lab var ID2 "Ideology of your party"
//lab var church_attend "Attendance to the church (5-point scale, 5 is highest)"
lab var religious "Religious (dummy 1 if believer)"
lab var rel_evangelical "Evangelical (dummy 1 if evangelical, 0 if religious but not evangelical)"
lab var rel_catholic "Catholics (dummy 1 if catholic, 0 if religious but not catholic)"
lab var rel_other "Religious Other (dummy 1 if other, 0 if religious but not other)"
lab var val_abortion "Opinion about abortion (1-10 scale, 10 is most in favor)"
//lab var val_ssm "Opinion about SSM (1-10 scale, 10 most in favor)"
//lab var val_drugs "Opinion about drug legalization (1-10 scale, 10 most in favor)"
//lab var val_imm "Immigrants compete for natives' jobs (1 disagree, 5 agree)"
lab var eco_regulated "Regulate Economy (1-10 scale, 10 agree)"
lab var education "Highest level of education (6-point scale, 1 no education, 6 graduate studies)"
lab var female "Female (dummy 1 if woman)"
lab var age "Age (years)"
lab var eco_prices "Price control (1-4, 4 in favor of state  intervention)"
lab var eco_education_p "Free primary education  (1-4, 4 in favor of state  intervention)"
lab var eco_education_s "Free secondary education"
//lab var eco_inequaltiy "Regulate Inequality between rich and poor (1-7, 7 in favor)"
lab var eco_education_u "Free university education (1-7, 7 in favor)"
lab var eco_housing "Subsidize housing (1-4, 4 in favor)"
lab var eco_employment "Employment creation (1-7, 7 in favor)"
lab var eco_unemployment "Unemployment insurance  (1-4, 4 in favor)"
lab var eco_pensions "Pension  (1-7, 7 in favor)"
lab var eco_environment "(1-4, 4 in favor)"
//lab var eco_health "Whether the state should provide health services  (1, 7 in favor). "
lab var eco_necessity "(1-4, 4 in favor)"
//lab var eco_wellbeing "Whether the state should guarantee basic wellbeing  (1, 7 in favor). "
//lab var eco_companies "Whether the state should own companies  (1, 5). "
//lab var eco_services "Whether the state should  control public services  (1, 5)."
lab var eco_private "Whether the state should privatize state industries  (1 in favor, 5 against). "
//lab var eco_natural ""
lab var eco_tax "Whether legislator prefers direct or indirect taxes (1=direct, 2=indirect, 3=no more tax)"
lab var val_religious "Degree of religiosity and secularity in public policies (1 Christian, 5 secular). "
lab var val_divorce "Opinion about divorce (1 against, 10 in favor). "

}
*****************************************************************
* Keep Variables
***************************************************************** 
{ 
	keep  wave eco_regulated education female age eco_prices eco_education_p eco_education_s  eco_education_u eco_housing eco_employment eco_unemployment eco_pensions eco_environment  eco_necessity    eco_private  eco_tax val_religious val_divorce nestu pais partido legis ID1 ID2  religious rel_catholic rel_other val_abortion rel_evangelical
	

}

*****************************************************************
* Save
***************************************************************** 
save "Bolivia_2002_2006.dta", replace
}


*****************************************************************
* Bolivia_2006_2010
*****************************************************************
{
clear
*Calling the data 
 import spss using  ".\Bolivia\BASEDATOS_BOLIVIA_62.sav", clear
 
*****************************************************************
* Recoding Variables
***************************************************************** 
{
 /*
 
 
 
 */
gen wave=2
drop legis 
gen legis = 2010

* Ideology 
gen ID1 = p64 // 1 left 
replace ID1=. if  p64>11
* Ideology Party
gen ID2=p65 // 1 left 
replace ID2=. if  p65>11

*--------------------------
* Party
*--------------------------
gen party = "."
replace party = "BOL_MNR" if partido ==2 
replace party = "BOL_UN" if partido ==3
replace party = "BOL_PODEMOS" if partido ==4
replace party = "BOL_MAS" if partido ==1
replace party = "BOL_Other" if partido>7

drop partido 

gen partido=party


// Attendance to church
//gen church_attend=RE1b





*--------------------------
* Abortion
*--------------------------
replace p70 =. if p70>11
gen VAL2_2=p70
gen val_abortion=round(VAL2_2)
lab define VAL221 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_abortion VAL221




*-----------------------
* Divorce
*-----------------------
gen val_divorce = p69 if p69<11
lab define div ///
	1 "Against" ///
	10 "In favor"
lab val val_divorce div





*--------------------------
* Religious
*--------------------------
* Religious label  Are you a  believer?
* Religious
gen religious=1 if p66==1
replace religious=0 if p66==2
replace religious=. if p66>3

lab define bel ///
	0 "Nonbeliever" ///
	1 "Believer"
lab val religious bel

*--------------------------
* Religious Evangelical
*--------------------------
gen rel_evangelical=1 if p66a==3
replace rel_evangelical=0 if religious==1 & rel_evangelical~=1

*--------------------------
* Religious Catholic
*--------------------------
gen rel_catholic=1 if p66a==1
replace rel_catholic=0 if religious==1 & rel_catholic~=1

*--------------------------
* Religious Other
*--------------------------
gen rel_other=1 if p66a~=1 & p66a~=3 & religious==1 &  p66a~=.
replace rel_other=0 if religious==1 & rel_catholic==1
replace rel_other=0 if religious==1 & rel_evangelical==1

*--------------------------
* Education
*--------------------------
gen education= p63 if  p63<8


lab define uni312 ///
	1 "No education" ///
	6 "Graduate studies"
lab val education uni312

*--------------------------
* Gender
*--------------------------
gen female=1 if p67==2
replace female=0 if p67==1

* Sex label
lab define UNION ///
	0 "Men" ///
	1 "Women"
lab val female UNION

*--------------------------
* Age
*--------------------------
gen age=p68 if p68<100



*-----------------------
* Economy regulada
*-----------------------
gen eco_regulated=p28*2 if p28<6
lab define EMI_2 ///
	1 "State" ///
	10 "Market"
lab val eco_regulated EMI_2

*-----------------------
* Free education university
*-----------------------
gen eco_education_u=round(p2907*7/4) if  p2907<8
lab define eco_education_u ///
	1 "Against" ///
	7 "In Favor"
lab val eco_education_u eco_education_u

*-----------------------
* Price control
*-----------------------
gen eco_prices= round(p2901) if p2901<7

lab define eco_prices ///
	1 "Against" ///
	4 "In Favor"
lab val eco_prices eco_prices

*-----------------------
* Free education primary
*-----------------------
gen eco_education_p= round(p2902) if p2902<7

lab val eco_education_p eco_prices

*-----------------------
* Free education secondary
*-----------------------
gen eco_education_s= round(p2902) if p2902<7

lab val eco_education_s eco_prices

*-----------------------
* Subside to housing
*-----------------------
gen eco_housing= round(p2903) if p2903<7

lab val eco_housing eco_prices

*-----------------------
* Employment
*-----------------------
gen eco_employment= round(p2904*7/4) if p2904<7


lab val eco_employment eco_education_u2



*-----------------------
* Pensions
*-----------------------
gen eco_pensions= round(p2905*7/4) if p2905<7


lab val eco_pensions eco_education_u2

*-----------------------
* State health
*-----------------------
gen eco_health=round(p2906*7/4) if p2906<7


lab val eco_health eco_education_u2



gen pais="Bolivia"


*-----------------------
* Tax
*-----------------------
gen eco_tax = p33 if p33<6
lab define taxes ///
	1 "Direct" ///
	2 "Indirect" ///
	3 "No more taxes"
lab val eco_tax taxes

}
// Labeling variables
{
lab var nestu "Study number"
lab var pais "Country name"
lab var partido "Party name (alphanumeric)"
lab var legis "Legislature"
lab var ID1 "Ideology"
lab var ID2 "Ideology of your party"
//lab var church_attend "Attendance to the church (5-point scale, 5 is highest)"
lab var religious "Religious (dummy 1 if believer)"
lab var rel_evangelical "Evangelical (dummy 1 if evangelical, 0 if religious but not evangelical)"
lab var rel_catholic "Catholics (dummy 1 if catholic, 0 if religious but not catholic)"
lab var rel_other "Religious Other (dummy 1 if other, 0 if religious but not other)"
lab var val_abortion "Opinion about abortion (1-10 scale, 10 is most in favor)"
//lab var val_ssm "Opinion about SSM (1-10 scale, 10 most in favor)"
//lab var val_drugs "Opinion about drug legalization (1-10 scale, 10 most in favor)"
//lab var val_imm "Immigrants compete for natives' jobs (1 disagree, 5 agree)"
lab var eco_regulated "Regulate Economy (1-10 scale, 10 agree)"
lab var education "Highest level of education (6-point scale, 1 no education, 6 graduate studies)"
lab var female "Female (dummy 1 if woman)"
lab var age "Age (years)"
lab var eco_prices "Price control (1-4, 4 in favor of state  intervention)"
lab var eco_education_p "Free primary education  (1-4, 4 in favor of state  intervention)"
lab var eco_education_s "Free secondary education"
//lab var eco_inequaltiy "Regulate Inequality between rich and poor (1-7, 7 in favor)"
lab var eco_education_u "Free university education (1-7, 7 in favor)"
lab var eco_housing "Subsidize housing (1-4, 4 in favor)"
lab var eco_employment "Employment creation (1-7, 7 in favor)"
//lab var eco_unemployment "Unemployment insurance  (1-4, 4 in favor)"
lab var eco_pensions "Pension  (1-7, 7 in favor)"
//lab var eco_environment "(1-4, 4 in favor)"
lab var eco_health "Whether the state should provide health services  (1, 7 in favor). "
//lab var eco_necessity "(1-4, 4 in favor)"
//lab var eco_wellbeing "Whether the state should guarantee basic wellbeing  (1, 7 in favor). "
//lab var eco_companies "Whether the state should own companies  (1, 5). "
//lab var eco_services "Whether the state should  control public services  (1, 5)."
//lab var eco_private "Whether the state should privatize state industries  (1 in favor, 5 against). "
//lab var eco_natural ""
lab var eco_tax "Whether legislator prefers direct or indirect taxes (1=direct, 2=indirect, 3=no more tax)"
//lab var val_religious "Degree of religiosity and secularity in public policies (1 Christian, 5 secular). "
lab var val_divorce "Opinion about divorce (1 against, 10 in favor). "

}
*****************************************************************
* Keep Variables
***************************************************************** 
{ 
	keep  eco_tax eco_health wave eco_regulated education female age eco_prices eco_education_p eco_education_s  eco_education_u eco_housing eco_employment  eco_pensions         eco_tax  val_divorce nestu pais partido legis ID1 ID2  religious rel_catholic rel_other val_abortion rel_evangelical
	

}

*****************************************************************
* Save
***************************************************************** 
save "Bolivia_2006_2010.dta", replace
}
*****************************************************************

*****************************************************************
* Bolivia_2010_2014
*****************************************************************
{
clear
*Calling the data 2015_2020
 import spss using  ".\Bolivia\BASEDATOS_BOLIVIA_81.sav", clear
 
*****************************************************************
* Recoding Variables
***************************************************************** 
{
 /*
 
 
 */
gen wave=3
drop legis 
gen legis = 2014

* Ideology 
replace ID1=. if  ID1>11
* Ideology Party
replace ID2=. if  ID2>11


// Attendance to church
gen church_attend=RE1b

gen regular=1 if RE1b==3 | RE1b==4 | RE1b==5
replace regular=0 if RE1b==1 | RE1b==2 

*--------------------------
* Party
*--------------------------
gen party = "."
replace party = "BOL_PPB" if partido ==2 
replace party = "BOL_MAS" if partido ==1
replace party = "BOL_Other" if partido>2

drop partido 

gen partido=party
*--------------------------
* Abortion
*--------------------------
replace VAL2 =. if VAL2>10
gen VAL2_2=VAL2
gen val_abortion=round(VAL2_2)
lab define VAL221 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_abortion VAL221

/*
*--------------------------
* Immigration
*--------------------------
replace INM101 =. if INM101>6
gen val_imm=INM101
lab define VAL21 ///
	1 "Totally against" ///
	5 "Totally agree"
lab val val_imm VAL21
*/
*--------------------------
* SSM
*--------------------------
replace VAL1 =. if VAL1>10
gen val_ssm=VAL1
lab define VAL1 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_ssm VAL1
/*
*--------------------------
* Drugs
*--------------------------
replace VAL3 =. if VAL3>10
gen val_drugs=VAL3

lab val val_drugs VAL1
*/
*--------------------------
* Religious
*--------------------------
* Religious label  Are you a  believer?
* Religious
gen religious=1 if RE1==1
replace religious=0 if RE1==2
replace religious=. if RE1>3

lab define bel ///
	0 "Nonbeliever" ///
	1 "Believer"
lab val religious bel

*--------------------------
* Religious Evangelical
*--------------------------
gen rel_evangelical=1 if RE1a==4
replace rel_evangelical=0 if religious==1 & rel_evangelical~=1

*--------------------------
* Religious Catholic
*--------------------------
gen rel_catholic=1 if RE1a==1
replace rel_catholic=0 if religious==1 & rel_catholic~=1

*--------------------------
* Religious Other
*--------------------------
gen rel_other=1 if RE1a~=1 & RE1a~=4 & religious==1 &  RE1a~=.
replace rel_other=0 if religious==1 & rel_catholic==1
replace rel_other=0 if religious==1 & rel_evangelical==1

*--------------------------
* Education
*--------------------------
gen education= SOCD7 if  SOCD7<9


lab define uni312 ///
	1 "No education" ///
	6 "Graduate studies"
lab val education uni312

*--------------------------
* Gender
*--------------------------
gen female=1 if SOCD4==2
replace female=0 if SOCD4==1

* Sex label
lab define UNION ///
	0 "Men" ///
	1 "Women"
lab val female UNION

*--------------------------
* Age
*--------------------------
gen age=SOCD5 if SOCD5<100

*-----------------------
* Economy regulada
*-----------------------
gen eco_regulated=EM1
lab define EMI_2 ///
	1 "State" ///
	10 "Market"
lab val eco_regulated EMI_2

*-----------------------
* Free education university
*-----------------------
gen eco_education_u=ROES107 if  ROES107<8
lab define eco_education_u ///
	1 "Against" ///
	7 "In Favor"
lab val eco_education_u eco_education_u

*-----------------------
* State should reduce inequality
*-----------------------
gen eco_inequaltiy=ROES104  if  ROES104<8

lab val eco_inequaltiy eco_education_u

*-----------------------
* State should create employment
*-----------------------
gen eco_employment=ROES103   if  ROES103 <8

lab val eco_employment eco_education_u

*-----------------------
* State companies
*-----------------------
gen eco_companies=ROES101    if  ROES101  <8

lab val eco_companies eco_education_u

*-----------------------
* State wellbeing
*-----------------------
gen eco_wellbeing=ROES102     if  ROES102   <8

lab val eco_wellbeing eco_education_u

*-----------------------
* State health
*-----------------------
gen eco_health=ROES106      if  ROES106    <8

lab val eco_health eco_education_u

*-----------------------
* Pensions
*-----------------------
gen eco_pensions=ROES105       if  ROES105     <8

lab val eco_pensions eco_education_u

}

// Labeling variables
{
lab var nestu "Study number"
lab var pais "Country name"
lab var partido "Party name (alphanumeric)"
lab var legis "Legislature"
lab var ID1 "Ideology"
lab var ID2 "Ideology of your party"
lab var church_attend "Attendance to the church (5-point scale, 5 is highest)"
lab var religious "Religious (dummy 1 if believer)"
lab var rel_evangelical "Evangelical (dummy 1 if evangelical, 0 if religious but not evangelical)"
lab var rel_catholic "Catholics (dummy 1 if catholic, 0 if religious but not catholic)"
lab var rel_other "Religious Other (dummy 1 if other, 0 if religious but not other)"
lab var val_abortion "Opinion about abortion (1-10 scale, 10 is most in favor)"
lab var val_ssm "Opinion about SSM (1-10 scale, 10 most in favor)"
//lab var val_drugs "Opinion about drug legalization (1-10 scale, 10 most in favor)"
//lab var val_imm "Immigrants compete for natives' jobs (1 disagree, 5 agree)"
lab var eco_regulated "Regulate Economy (1-10 scale, 10 agree)"
lab var education "Highest level of education (6-point scale, 1 no education, 6 graduate studies)"
lab var female "Female (dummy 1 if woman)"
lab var age "Age (years)"
lab var eco_inequaltiy "Regulate Inequality between rich and poor (1-7, 7 in favor)"
lab var eco_education_u "Free university education (1-7, 7 in favor)"
lab var eco_employment "Employment creation (1-7, 7 in favor)"
lab var eco_pensions "Pension"
lab var eco_health "Whether the state should own provide health services  (1, 7 in favor)"
lab var eco_wellbeing "Whether the state should guarantee basic wellbeign  (1, 7 in favor)"
lab var eco_companies "Whether the state should own companies  (1, 5)"

}
*****************************************************************
* Keep Variables
***************************************************************** 
{ 
	keep wave nestu pais partido legis ID1 ID2 church_attend religious rel_evangelical rel_catholic rel_other val_abortion val_ssm   eco_regulated education female age eco_inequaltiy eco_education_u eco_employment eco_pensions eco_health eco_wellbeing eco_companies

}


*****************************************************************
* Save
***************************************************************** 
save "Bolivia_2010_2014.dta", replace
}
*****************************************************************
* Bolivia_2015_2020
*****************************************************************
{
clear
*Calling the data 2015_2020
 import spss using  ".\Bolivia\BASEDATOS_BOLIVIA_98.sav", clear
 
*****************************************************************
* Recoding Variables
***************************************************************** 
{
 /*
 
 
 */
gen wave=4
drop legis 
gen legis = 2020

* Ideology 
replace ID1=. if  ID1>11
* Ideology Party
replace ID2=. if  ID2>11


// Attendance to church
gen church_attend=RE1B

gen regular=1 if RE1B==3 | RE1B==4 | RE1B==5
replace regular=0 if RE1B==1 | RE1B==2 

*--------------------------
* Party
*--------------------------
gen party = "."
replace party = "BOL_UD" if partido ==41
replace party = "BOL_MAS" if partido ==36
replace party = "BOL_PDC" if partido==42

drop partido 

gen partido=party
*--------------------------
* Abortion
*--------------------------
replace VAL2 =. if VAL2>10
gen VAL2_2=VAL2
gen val_abortion=round(VAL2_2)
lab define VAL221 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_abortion VAL221


*--------------------------
* Immigration
*--------------------------
replace INM101 =. if INM101>6
gen val_imm=INM101
lab define VAL21 ///
	1 "Totally against" ///
	5 "Totally agree"
lab val val_imm VAL21

*--------------------------
* SSM
*--------------------------
replace VAL1 =. if VAL1>10
gen val_ssm=VAL1
lab define VAL1 ///
	1 "Totally against" ///
	10 "Totally agree"
lab val val_ssm VAL1

*--------------------------
* Drugs
*--------------------------
replace VAL3 =. if VAL3>10
gen val_drugs=VAL3

lab val val_drugs VAL1

*--------------------------
* Religious
*--------------------------
* Religious label  Are you a  believer?
* Religious
gen religious=1 if RE1==1
replace religious=0 if RE1==2
replace religious=. if RE1>3

lab define bel ///
	0 "Nonbeliever" ///
	1 "Believer"
lab val religious bel

*--------------------------
* Religious Evangelical
*--------------------------
gen rel_evangelical=1 if RE1A==17
replace rel_evangelical=0 if religious==1 & rel_evangelical~=1

*--------------------------
* Religious Catholic
*--------------------------
gen rel_catholic=1 if RE1A==1
replace rel_catholic=0 if religious==1 & rel_catholic~=1

*--------------------------
* Religious Other
*--------------------------
gen rel_other=1 if RE1A~=1 & RE1A~=17 & religious==1 &  RE1A~=.
replace rel_other=0 if religious==1 & rel_catholic==1
replace rel_other=0 if religious==1 & rel_evangelical==1

*--------------------------
* Education
*--------------------------
gen education= SOCD7 if  SOCD7<9


lab define uni312 ///
	1 "No education" ///
	6 "Graduate studies"
lab val education uni312

*--------------------------
* Gender
*--------------------------
gen female=1 if SOCD4==2
replace female=0 if SOCD4==1

* Sex label
lab define UNION ///
	0 "Men" ///
	1 "Women"
lab val female UNION

*--------------------------
* Age
*--------------------------
gen age=SOCD5 if SOCD5<100

*-----------------------
* Economy regulada
*-----------------------
gen eco_regulated=EM1
lab define EMI_2 ///
	1 "State" ///
	10 "Market"
lab val eco_regulated EMI_2

*-----------------------
* Free education university
*-----------------------
gen eco_education_u=ROES107 if  ROES107<8
lab define eco_education_u ///
	1 "Against" ///
	7 "In Favor"
lab val eco_education_u eco_education_u

*-----------------------
* State should reduce inequality
*-----------------------
gen eco_inequaltiy=ROES104  if  ROES104<8

lab val eco_inequaltiy eco_education_u

*-----------------------
* State should create employment
*-----------------------
gen eco_employment=ROES103   if  ROES103 <8

lab val eco_employment eco_education_u

*-----------------------
* State companies
*-----------------------
gen eco_companies=ROES101    if  ROES101  <8

lab val eco_companies eco_education_u

*-----------------------
* State wellbeing
*-----------------------
gen eco_wellbeing=ROES102     if  ROES102   <8

lab val eco_wellbeing eco_education_u

*-----------------------
* State health
*-----------------------
gen eco_health=ROES106      if  ROES106    <8

lab val eco_health eco_education_u

*-----------------------
* Pensions
*-----------------------
gen eco_pensions=ROES105       if  ROES105     <8

lab val eco_pensions eco_education_u

}

// Labeling variables
{
lab var nestu "Study number"
lab var pais "Country name"
lab var partido "Party name (alphanumeric)"
lab var legis "Legislature"
lab var ID1 "Ideology"
lab var ID2 "Ideology of your party"
lab var church_attend "Attendance to the church (5-point scale, 5 is highest)"
lab var religious "Religious (dummy 1 if believer)"
lab var rel_evangelical "Evangelical (dummy 1 if evangelical, 0 if religious but not evangelical)"
lab var rel_catholic "Catholics (dummy 1 if catholic, 0 if religious but not catholic)"
lab var rel_other "Religious Other (dummy 1 if other, 0 if religious but not other)"
lab var val_abortion "Opinion about abortion (1-10 scale, 10 is most in favor)"
lab var val_ssm "Opinion about SSM (1-10 scale, 10 most in favor)"
lab var val_drugs "Opinion about drug legalization (1-10 scale, 10 most in favor)"
lab var val_imm "Immigrants compete for natives' jobs (1 disagree, 5 agree)"
lab var eco_regulated "Regulate Economy (1-10 scale, 10 agree)"
lab var education "Highest level of education (6-point scale, 1 no education, 6 graduate studies)"
lab var female "Female (dummy 1 if woman)"
lab var age "Age (years)"
lab var eco_inequaltiy "Regulate Inequality between rich and poor (1-7, 7 in favor)"
lab var eco_education_u "Free university education (1-7, 7 in favor)"
lab var eco_employment "Employment creation (1-7, 7 in favor)"
lab var eco_pensions "Pension"
lab var eco_health "Whether the state should own provide health services  (1, 7 in favor)"
lab var eco_wellbeing "Whether the state should guarantee basic wellbeign  (1, 7 in favor)"
lab var eco_companies "Whether the state should own companies  (1, 5)"

}
*****************************************************************
* Keep Variables
***************************************************************** 
{ 
	keep wave nestu pais partido legis ID1 ID2 church_attend religious rel_evangelical rel_catholic rel_other val_abortion val_ssm   eco_regulated education female age eco_inequaltiy eco_education_u eco_employment eco_pensions eco_health eco_wellbeing eco_companies

}


*****************************************************************
* Save
***************************************************************** 
save "Bolivia_2015_2020.dta", replace
}

*****************************************************************
* Append
***************************************************************** 
{
append using "Bolivia_2002_2006.dta", force
append using "Bolivia_2006_2010.dta", force
append using "Bolivia_2010_2014.dta", force
drop pais
gen pais = "Bolivia"
save "Bolivia_2002_2020.dta", replace
*****************************************************************
erase "Bolivia_2002_2006.dta"
erase "Bolivia_2006_2010.dta"
erase "Bolivia_2010_2014.dta"
erase "Bolivia_2015_2020.dta"

}

/*
* Extra Exploration data
{
******************************************************************************
* Graph setting
******************************************************************************
{
grstyle clear
set scheme s2color
grstyle init
grstyle set plain, box
grstyle color background white
grstyle set color dknavy
grstyle yesno draw_major_hgrid yes
grstyle yesno draw_major_ygrid yes
grstyle color major_grid gs8
grstyle linepattern major_grid dot
*grstyle set legend 4, box inside
grstyle color ci_area gs12%50
 graph set window fontface "Georgia"
}
 

histogram eco_regulated, by (legis partido) 


histogram val_abortion, by (legis partido) 
}
*/
